<template>
	<view>
		<button type="primary" @click="openCamera">使用摄像头拍照</button>
		<view>
			<image :src="picture" mode="aspectFit"></image>
		</view>
		<button @click="upload">人脸注册&下一步</button>
		<!-- <navigator url="/pages/bank-card/bank-card">
			<button>开发下一步</button>
		</navigator> -->
	</view>
</template>

<script>
// import { uploadFile } from '@/api/http.js';
import { faceReg } from '@/api/companyApi.js';
export default {
	data() {
		return {
			picture: ''
		};
	},
	methods: {
		openCamera() {
			uni.navigateTo({
				url: '/pages/playgroud/index',
				events: {
					onPageBurn: (res) => {
						console.log('监听到pageBurn发生,灰烬是', res);
						this.picture = res.photo;
					}
				}
			});
		},
		async upload() {
			// uni.uploadFile 都是post请求
			// filePath : http://tmp/MwHmvOxKzKhO4d910cd76390cffaf6f659ec676a8fe0.jpg
			// http: post  multipart/form-data
			// const token = uni.getStorageSync('token');
			// const header = {};
			// if (token) {
			// 	header.Authorization = token;
			// }
			// uni.uploadFile({
			// 	header: header,
			// 	filePath: this.picture,
			// 	name: 'file',
			// 	url: 'http://localhost:6060/company/face-reg',
			// 	success: (res) => {
			// 		console.log('上传成功', res);
			// 		console.log('上传完毕，开始新业务人脸认证');
			// 		uni.navigateTo({
			// 			url: '/pages/face-search/face-search'
			// 		});
			// 	}
			// });
			// const res = await uploadFile({
			// 	name: 'file',
			// 	filePath: this.picture,
			// 	url: '/company/face-reg'
			// });
			const res = await faceReg(this.picture);
			console.log('上传成功', res);
			console.log('上传完毕，开始新业务人脸认证');
			uni.navigateTo({
				url: '/pages/bank-card/bank-card'
			});
		}
	}
};
</script>

<style></style>
